#include "Deck.h"

Deck::Deck()
{
}

Deck::~Deck()
{
	clearDeck();
}
void Deck::addCard(Card * card)
{
	deck.push_back(card);
}

Card * Deck::getCardAt(unsigned position)
{
	if(position < deck.size())
	{
		return deck[position];
	}
	return 0;
}

void Deck::popBackCard()
{
	if(deck.size()>0)
		deck.pop_back();
}

void Deck::clearDeck()
{
	if(deck.size()>0)
		deck.clear();
}

vector<Card*>::iterator Deck::first()
{
	return deck.begin();
}

vector<Card*>::iterator Deck::last()
{
	return deck.end();
}


void Deck::removeCard(Card * card)
{
	for(it = deck.begin(); it<deck.end(); ++it)
	{
		if((*it)->rank == card->rank && (*it)->suit == card->suit)
		{
			it=deck.erase(it);
		}
	}
}

void Deck::shuffle()
{
	std::srand ( unsigned ( std::time(0) ) );
	std::random_shuffle(deck.begin(), deck.end());
}

void Deck::printCards(bool symbol, bool suit, bool rank)
{
	for(it=deck.begin(); it!=deck.end(); ++it)
	{
		if(symbol)
			std::cout<<"Symbol: " << (*it)->symbol << "   ";
		if(suit)
			std::cout<<"Suit: " << (*it)->suit << "   ";
		if(rank)
			std::cout<<"Rank: " << (*it)->rank << "   ";
		std::cout << std::endl;
	}
}

void Deck::removeCardAt(unsigned position)
{
	if(position > deck.size())
		for(it = deck.begin(); it!=deck.end(); ++it)
		{
			if((*it)->rank == deck[position]->rank && (*it)->suit == deck[position]->suit)
			{
				deck.erase(it);
				break;
			}
		}
}

Card Deck::removeAndGetCardAt(unsigned position)
{
	Card card;
	if(position > deck.size())
		for(it = deck.begin(); it!=deck.end(); ++it)
		{
			if((*it)->rank == deck[position]->rank && (*it)->suit == deck[position]->suit)
			{
				card = *(*it);
				deck.erase(it);
				break;
			}
		}
	return card;
}

unsigned int Deck::getDeckSize()
{
	return deck.size();
}

